package com.vhall.component.controller.record;

import com.alibaba.fastjson.JSONObject;
import com.vhall.component.controller.record.facade.RecordAdminFacade;
import com.vhall.component.entity.record.vo.*;
import com.vhall.component.framework.common.annotation.VhallComponent;
import com.vhall.component.framework.common.constant.CommonConstant;
import com.vhall.component.plugin.common.annotation.TokenAuth;
import com.vhall.component.plugin.common.annotation.TokenAuth;
import com.vhall.component.service.record.RecordService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;

import java.util.ArrayList;
import java.util.List;

/**
 * @author dongsong
 */
@TokenAuth
@VhallComponent
public class RecordAdminController implements RecordAdminFacade {

    @Autowired
    private RecordService recordService;

    /**
     * 运营后台获取回放列表
     */
    @Override
    @TokenAuth("sys:record:list")
    public GetRecordListRspVo list(@Validated GetRecordListReqVo reqVo) {
        return recordService.getRecordList(reqVo);
    }

    /**
     * 运营后台设置默认回放
     */
    @Override
    @TokenAuth("sys:room:record")
    public List<Object> setDefaultRecord(@Validated SetDefaultRecordReqVo reqVo) {
        recordService.setDefaultRecord(reqVo);
        return new ArrayList<>();
    }

    /**
     * 运营后台删除回放
     */
    @Override
    @TokenAuth("sys:record:del")
    public JSONObject delete(@Validated DeleteRecordReqVo reqVo) {
        return recordService.deleteRecord(reqVo);
    }

    /**
     * 运营后台获取回放信息
     */
    @Override
    @TokenAuth("sys:record:info")
    public GetRecordRspVo get(@Validated GetRecordReqVo reqVo) {
        return recordService.getRecord(reqVo);
    }

    /**
     * 媒资管理-音视频管理-获取回放列表
     */
    @Override
    public GetUploadListRspVo uploadList(@Validated GetUploadListReqVo reqVo) {
        if (StringUtils.isNotEmpty(reqVo.getSearch())) {
            String search = reqVo.getSearch();
            if (reqVo.getSearch().contains(CommonConstant.UNDERLINE)) {
                search = reqVo.getSearch().replace(CommonConstant.UNDERLINE, "\\" + CommonConstant.UNDERLINE);
            }
            if (reqVo.getSearch().contains(CommonConstant.PERCENT_SIGN)) {
                search = search.replace(CommonConstant.PERCENT_SIGN, "\\" + CommonConstant.PERCENT_SIGN);
            }
            reqVo.setSearch(search);
        }
        return recordService.getUploadList(reqVo, null);
    }

    @Override
    @TokenAuth
    public Boolean add(GetRecordListReqVo reqVo) {
        return recordService.addRecord(reqVo);
    }
}
